package com.frejoys.common.util;

import cn.hutool.core.util.ReUtil;
import com.frejoys.common.error.HttpStatus;
import com.frejoys.common.exception.GeneralException;

public class CheckUtil {

    // 手机号码长度
    private static int phoneLength = 11;

    // 手机正则
    private static String regex = "^1[3-9]\\d{9}$";

    // 最大
    private static int passwordMax = 12;

    // 最小
    private static int passwordMin = 6;

    // 验证码长度
    private static int codeLength = 6;

    /**
     * 号码验证
     * @param phone
     */
    public static void phone(String phone) {
        if (phone.length() != phoneLength) {
            throw new GeneralException(HttpStatus.phoneLengthError);
        }

        if (!ReUtil.isMatch(regex, phone)) {
            throw new GeneralException(HttpStatus.phoneError);
        }
    }

    /**
     * email验证
     * @param email
     */
    public static void email(String email) {

    }

    /**
     * 密码验证
     * @param phone
     */
    public static void password(String phone) {
        if (passwordMin > phone.length() || passwordMax < phone.length()) {
            throw new GeneralException(HttpStatus.passwordLengthError);
        }
    }

    /**
     * 验证码验证
     * @param code
     */
    public static void code(String code) {
        if (codeLength != code.length()) {
            throw new GeneralException(HttpStatus.codeLengthVerifyError);
        }
    }

}
